<?php
//include file
include("../include/session.php");
require_once('../db_conn/conn_db.php');

$action 	  = $_GET['action'];
$id 		  = $_GET['id'];
$nama		  = $_POST['nama'];
$alamat 	  = $_POST['alamat'];
$no_tlp   	  = $_POST['no_tlp'];
$user		 	= $_POST['username'];
$password		= $_POST['pass'];
$role 			= $_POST['role'];

if ($action=="update") {

	$sql_update = "update Karyawan set nama = '$namaKaryawan', id_karyawan = '$nik',
				  tmk = '$tmk',kode_jabatan='$jabatan',no_tlp='$noTelp',alamat='$alamat', 
				  no_rekening='$noRek',nama_bank='$namaBank',keterangan_bang='$ketBank',no_jamsostek='$noJamsostek',
				  no_npwp='$npwp' where id_karyawan='$nik' ";

//echo "$sql_update";
//exit;

$result_update = mysql_query($sql_update) 
		or die("Gagal Query. Error :".mysql_error());


echo 
				"<script language=\"JavaScript\">
				alert(\"Data Sukses di Update \" ,\"Pesan\");
				location.href = \"view_klien.php\"
				</script>";
 }

else if ($action=="delete") {
	$sql_delete = "update karyawan set status_karyawan = '99' where id_karyawan='$id' ";

//echo "$sql_delete";
//exit;

	$result_delete = mysql_query($sql_delete) 
			or die("Gagal Query. Error :".mysql_error());
	
	
	echo 
					"<script language=\"JavaScript\">
					alert(\"Data Sukses di Hapus\" ,\"Pesan\");
					location.href = \"view_klien.php\"
					</script>";
		//echo "delete";
		//exit;
}
else if ($action == "su") {
	$sql_user = "insert into user values ('','$user',md5('$password'),'$role','1',now())";

	$sql_result = mysql_query($sql_user) 
			or die("Gagal Query. Error :".mysql_error());
	
	echo 
	"<script language=\"JavaScript\">
	alert(\"Data Sukses di Input \" ,\"Pesan\");
	location.href = \"view_user.php\"
	</script>";
}
else 
{

	$sql_user = "insert into user values ('','$user',md5('$password'),'2','1',now())";

	$sql_result = mysql_query($sql_user) 
			or die("Gagal Query. Error :".mysql_error());
	
	$id = mysql_result(mysql_query("SELECT id FROM user where username='$user' LIMIT 1"),0);
	
	$sql_query = "insert into klien values ('','$id','$nama','$alamat','$no_tlp','1',now())";

	$sql_result = mysql_query($sql_query) 
			or die("Gagal Query. Error :".mysql_error());

	echo 
	"<script language=\"JavaScript\">
	alert(\"Data Sukses di Input \" ,\"Pesan\");
	location.href = \"view_klien.php\"
	</script>";
				
}
		
?>